const Koa = require('koa')
const app = new Koa()
const mongoose = require('mongoose')
const config = require('./server/config/config')

// middleware
const middleware = require('./server/middleware/')
middleware(app)

// controller
const index = require('./server/controller/index')
const game = require('./server/controller/game')

// routes controller
app.use(index.routes(), index.allowedMethods())
app.use(game.routes(), game.allowedMethods())

// mongodb odm
mongoose.connect(config.mongo, {
  useNewUrlParser: true,
  useUnifiedTopology: true
})

module.exports = app
